/**
 * Copyright (c) 2016-2021 by the respective copyright holders.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package com.zsmartsystems.zigbee.dongle.telegesis.internal.protocol;

import com.zsmartsystems.zigbee.IeeeAddress;
import com.zsmartsystems.zigbee.dongle.telegesis.internal.protocol.TelegesisStatusCode;
import java.util.ArrayList;
import java.util.List;

/**
 * Class to implement the Telegesis command <b>Address Response</b>.
 * <p>
 * Response  to  an  address  request  (also  triggered when finding source routes)
 * <p>
 * This class provides methods for processing Telegesis AT API commands.
 * <p>
 * Note that this code is autogenerated. Manual changes may be overwritten.
 *
 * @author Chris Jackson - Initial contribution of Java code generator
 */
public class TelegesisAddressResponseEvent extends TelegesisFrame implements TelegesisEvent {
    /**
     * AddrResp response field
     */
    private TelegesisStatusCode status;

    /**
     * AddrResp response field
     */
    private IeeeAddress ieeeAddress;

    /**
     * AddrResp response field
     */
    private Integer networkAddress;

    /**
     * AddrResp response field
     */
    private List<Integer> associatedDevices = new ArrayList<Integer>();

    /**
     *
     * @return the status as {@link TelegesisStatusCode}
     */
    public TelegesisStatusCode getStatus() {
        return status;
    }

    /**
     *
     * @return the ieeeAddress as {@link IeeeAddress}
     */
    public IeeeAddress getIeeeAddress() {
        return ieeeAddress;
    }

    /**
     *
     * @return the networkAddress as {@link Integer}
     */
    public Integer getNetworkAddress() {
        return networkAddress;
    }

    /**
     *
     * @return the associatedDevices as {@link List} of {@link Integer}
     */
    public List<Integer> getAssociatedDevices() {
        return associatedDevices;
    }


    @Override
    public void deserialize(int[] data) {
        initialiseDeserializer(data);

        // Deserialize the fields for the "AddrResp" response
        if (testPrompt(data, "AddrResp:")) {
            setDeserializer(9);

            // Deserialize field "status"
            status = deserializeTelegesisStatusCode();
            stepDeserializer();

            // Deserialize field "ieee Address"
            ieeeAddress = deserializeIeeeAddress();
            stepDeserializer();

            // Deserialize field "network Address"
            networkAddress = deserializeInt16();
            stepDeserializer();

            // Deserialize field "associated devices"
            while (true) {
                Integer tmpAssociatedDevices = deserializeInt16();
                if (tmpAssociatedDevices == null) {
                    break;
                }
                stepDeserializer();
                associatedDevices.add(tmpAssociatedDevices);
            }
        }
    }

    @Override
    public String toString() {
        final StringBuilder builder = new StringBuilder(479);
        builder.append("TelegesisAddressResponseEvent [status=");
        builder.append(status);
        builder.append(", ieeeAddress=");
        builder.append(ieeeAddress);
        builder.append(", networkAddress=");
        builder.append(networkAddress);
        builder.append(", associatedDevices=");
        builder.append(associatedDevices);
        builder.append(']');
        return builder.toString();
    }
}
